package com.systemsjr.jrhabit;

import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

public enum RepeatEnum {

	HOURS("HOURS"),
	DAYS("DAYS"),
	WEEKS("WEEKS"),
	MONTHS("MONTHS"),
	YEARS("YEARS");
	
	private final String enumValue;
	
	private RepeatEnum(String enumValue){
		this.enumValue = enumValue;
	}
	
	/**
     * Retrieves an instance of RepeatEnum from <code>its name</code>.
     *
     * @param name the name to create the RepeatEnum from.
     * @return The enumeration literal named after the 'name' argument
     */
    public static RepeatEnum fromString(String name)
    {
        return RepeatEnum.valueOf(name);
    }

    /**
     * Returns an enumeration literal String <code>value</code>.
     * Required by JAXB2 enumeration implementation
     *
     * @return String with corresponding value
     */
    public String value()
    {
        return this.enumValue;
    }

    /**
     * Returns an instance of RepeatEnum from String <code>value</code>.
     * Required by JAXB2 enumeration implementation
     *
     * @param value the value to create the RepeatEnum from.
     * @return static Enumeration with corresponding value
     */
    public static RepeatEnum fromValue(String value)
    {
        for (RepeatEnum enumName: RepeatEnum.values())
        {
            if (enumName.getValue().equals(value))
            {
                return enumName;
            }
        }
        throw new IllegalArgumentException("RepeatEnum.fromValue(" + value + ')');
    }

    /**
     * Gets the underlying value of this type safe enumeration.
     * This method is necessary to comply with DaoBase implementation.
     * @return The name of this literal.
     */
    public String getValue()
    {
        return this.enumValue;
    }

    /**
     * Returns an unmodifiable list containing the literals that are known by this enumeration.
     *
     * @return A List containing the actual literals defined by this enumeration, this list
     *         can not be modified.
     */
    public static List<String> literals()
    {
        return RepeatEnum.literals;
    }

    /**
     * Returns an unmodifiable list containing the names of the literals that are known
     * by this enumeration.
     *
     * @return A List containing the actual names of the literals defined by this
     *         enumeration, this list can not be modified.
     */
    public static List<String> names()
    {
        return RepeatEnum.names;
    }

    private static Map<String, RepeatEnum> values = new LinkedHashMap<String, RepeatEnum>(5, 1);
    private static List<String> literals = new ArrayList<String>(5);
    private static List<String> names = new ArrayList<String>(5);
    private static List<RepeatEnum> valueList = new ArrayList<RepeatEnum>(5);

    /**
     * Initializes the values.
     */
    static
    {
        synchronized (RepeatEnum.values)
        {
            RepeatEnum.values.put(HOURS.enumValue, HOURS);
            RepeatEnum.values.put(DAYS.enumValue, DAYS);
            RepeatEnum.values.put(WEEKS.enumValue, WEEKS);
            RepeatEnum.values.put(MONTHS.enumValue, MONTHS);
            RepeatEnum.values.put(YEARS.enumValue, YEARS);
        }
        synchronized (RepeatEnum.valueList)
        {
            RepeatEnum.valueList.add(HOURS);
            RepeatEnum.valueList.add(DAYS);
            RepeatEnum.valueList.add(WEEKS);
            RepeatEnum.valueList.add(MONTHS);
            RepeatEnum.valueList.add(YEARS);
            RepeatEnum.valueList = Collections.unmodifiableList(valueList);
        }
        synchronized (RepeatEnum.literals)
        {
            RepeatEnum.literals.add(HOURS.enumValue);
            RepeatEnum.literals.add(DAYS.enumValue);
            RepeatEnum.literals.add(WEEKS.enumValue);
            RepeatEnum.literals.add(MONTHS.enumValue);
            RepeatEnum.literals.add(YEARS.enumValue);
            RepeatEnum.literals = Collections.unmodifiableList(literals);
        }
        synchronized (RepeatEnum.names)
        {
            RepeatEnum.names.add("HOURS");
            RepeatEnum.names.add("DAYS");
            RepeatEnum.names.add("WEEKS");
            RepeatEnum.names.add("MONTHS");
            RepeatEnum.names.add("YEARS");
            RepeatEnum.names = Collections.unmodifiableList(names);
        }
    }
}
